package com.jjyu.controller;

import com.jjyu.entity.Feedback;
import com.jjyu.service.FeedbackService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/feedback") // 定义反馈管理的基础路径
@Tag(name = "反馈管理", description = "用户反馈相关接口")
public class FeedbackController {

    @Autowired
    private FeedbackService feedbackService; // 注入反馈服务

    // 提交用户反馈
    @PostMapping(value = "/recommendations", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    public Feedback submitFeedback(@Valid @RequestBody Feedback feedback) {
        return feedbackService.submitFeedback(feedback);
    }

    // 获取所有反馈
    @GetMapping(value = "/all", produces = MediaType.APPLICATION_JSON_VALUE)
    public List<Feedback> getAllFeedbacks() {
        return feedbackService.getAllFeedbacks();
    }

    // 根据用户ID获取反馈
    @GetMapping(value = "/user/{userId}", produces = MediaType.APPLICATION_JSON_VALUE)
    public List<Feedback> getFeedbacksByUserId(@PathVariable Integer userId) {
        return feedbackService.getFeedbacksByUserId(userId);
    }

    // 根据推荐内容ID获取反馈
    @GetMapping(value = "/recommendation/{recommendationId}", produces = MediaType.APPLICATION_JSON_VALUE)
    public List<Feedback> getFeedbacksByRecommendationId(@PathVariable Integer recommendationId) {
        return feedbackService.getFeedbacksByRecommendationId(recommendationId);
    }

    // 更新反馈
    @PutMapping(value = "/{id}", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    public Feedback updateFeedback(@PathVariable Long id, @Valid @RequestBody Feedback feedback) {
        return feedbackService.updateFeedback(id, feedback);
    }
}